/**
 * gridstack SASS styles 10.3.0-dev
 * Copyright (c) 2021 Alain Dumesny - see GridStack root license
 */

$columns: 12 !default;
$animation_speed: .3s !default;

@function fixed($float) {
  @return calc(round($float * 1000) / 1000); // total 4-5 digits being %
}

@mixin vendor($property, $value...){
  // -webkit-#{$property}: $value;
  // -moz-#{$property}: $value;
  // -ms-#{$property}: $value;
  // -o-#{$property}: $value;
  #{$property}: $value;
}

.grid-stack {
  position: relative;
}

.grid-stack-rtl {
  direction: ltr;
  > .grid-stack-item {
    direction: rtl;
  }
}

.grid-stack-placeholder > .placeholder-content {
  background-color: rgba(0,0,0,0.1);
  margin: 0;
  position: absolute;
  width: auto;
  z-index: 0 !important;
}

// make those more unique as to not conflict with side panel items
.grid-stack > .grid-stack-item {
  position: absolute;
  padding: 0;

  > .grid-stack-item-content {
    margin: 0;
    position: absolute;
    width: auto;
    overflow-x: hidden;
    overflow-y: auto;
  }
  &.size-to-content:not(.size-to-content-max) > .grid-stack-item-content {
    overflow-y: hidden;
  }
}

.grid-stack-item {
  > .ui-resizable-handle {
    position: absolute;
    font-size: 0.1px;
    display: block;
    -ms-touch-action: none;
    touch-action: none;
  }

  &.ui-resizable-disabled > .ui-resizable-handle,
  &.ui-resizable-autohide > .ui-resizable-handle { display: none; }

  > .ui-resizable-ne,
  > .ui-resizable-nw,
  > .ui-resizable-se,
  > .ui-resizable-sw {
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" fill="none" stroke="%23666" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" viewBox="0 0 20 20"><path d="m10 3 2 2H8l2-2v14l-2-2h4l-2 2"/></svg>');
    background-repeat: no-repeat;
    background-position: center;
  }

  > .ui-resizable-ne {
    @include vendor(transform, translate(0, 10px) rotate(45deg));
  }
  > .ui-resizable-sw {
    @include vendor(transform, rotate(45deg));
  }

  > .ui-resizable-nw {
    @include vendor(transform, translate(0, 10px) rotate(-45deg));
  }
  > .ui-resizable-se {
    @include vendor(transform, rotate(-45deg));
  }

  > .ui-resizable-nw { cursor: nw-resize; width: 20px; height: 20px; top: 0; }
  > .ui-resizable-n  { cursor: n-resize;  height: 10px; top: 0; left: 25px; right: 25px; }
  > .ui-resizable-ne { cursor: ne-resize; width: 20px; height: 20px; top: 0; }
  > .ui-resizable-e  { cursor: e-resize;  width: 10px; top: 15px; bottom: 15px; }
  > .ui-resizable-se { cursor: se-resize; width: 20px; height: 20px;}
  > .ui-resizable-s  { cursor: s-resize;  height: 10px; left: 25px; bottom: 0; right: 25px; }
  > .ui-resizable-sw { cursor: sw-resize; width: 20px; height: 20px;}
  > .ui-resizable-w  { cursor: w-resize;  width: 10px; top: 15px; bottom: 15px; }

  &.ui-draggable-dragging {
    &> .ui-resizable-handle {
      display: none !important;
    }
  }

  &.ui-draggable-dragging {
    will-change: left, top;
    cursor: move;
  }

  &.ui-resizable-resizing {
    will-change: width, height;
  }
}

// not .grid-stack-item specific to also affect dragIn regions
.ui-draggable-dragging,
.ui-resizable-resizing {
  z-index: 10000; // bootstrap modal has a z-index of 1050

  > .grid-stack-item-content {
    box-shadow: 1px 4px 6px rgba(0, 0, 0, 0.2);
    opacity: 0.8;
  }
}

.grid-stack-animate,
.grid-stack-animate .grid-stack-item {
  @include vendor(transition, left $animation_speed, top $animation_speed, height $animation_speed, width $animation_speed);
}

.grid-stack-animate .grid-stack-item.ui-draggable-dragging,
.grid-stack-animate .grid-stack-item.ui-resizable-resizing,
.grid-stack-animate .grid-stack-item.grid-stack-placeholder{
  @include vendor(transition, left 0s, top 0s, height 0s, width 0s);
}

// make those more unique as to not conflict with side panel items, but apply to all column layouts (so not in loop below)
.grid-stack > .grid-stack-item[gs-y="0"] {
  top: 0px;
}
.grid-stack > .grid-stack-item[gs-x="0"] {
  left: 0%;
}

.gs-#{$columns} > .grid-stack-item {
  width: fixed(calc(100% / $columns));
  @for $i from 1 through ($columns - 1) {
    &[gs-x='#{$i}'] { left: fixed(calc(100% / $columns) * $i); }
    &[gs-w='#{$i + 1}'] { width: fixed(calc(100% / $columns) * ($i + 1)); }
  }
}

.gs-1 > .grid-stack-item {
  width: 100%;
}
